package com.john.permission.service.impl;

import com.john.permission.mapper.UserMapper;
import com.john.permission.pojo.User;
import com.john.permission.pojo.UserExample;
import com.john.permission.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User checkUser(User userFromPage) {
        if(userFromPage.getUsername() == null) {
            return null;
        }
        UserExample condition = new UserExample();
        condition.createCriteria().andUsernameEqualTo(userFromPage.getUsername());
        List<User> users = userMapper.selectByExample(condition);
        if(users == null || users.size() < 1) {
            return null;
        }
        User userInDB = users.get(0);
        if(userInDB.getPassword().equals(userFromPage.getPassword())) {
            return userInDB;
        }
        return null;
    }
}
